<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class SystemUserLevel extends Model
{
    use HasFactory;
    use PimpableTrait;

    /**
     * 可进行搜索的字段
     */
    public $searchable = [
        'id',
        'merchant_id',
        'name',
        'valid_date',
        'grade',
        'is_forever',
        'is_pay',
        'is_show',
    ];

    /**
     *可批量赋值字段
     */
    public $fillable = [
        'merchant_id',
        'name',
        'money',
        'valid_date',
        'grade',
        'discount',
        'image',
        'icon',
        'explain',
        'exp_num',
        'system_admin_id',
    ];

    /**
     * 进行排序的字段
     */
    public $sortable = [
        'id',
        'merchant_id',
        'valid_date',
        'grade',
        'discount',
    ];

    /**
     * 默认倒叙的字段
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 进行模糊搜索的字段
     */
    public $searchableModels = [
        'name' => '%field%',
    ];


    /**
     * 用户等级记录所属用户
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id','id');
    }

    /**
     * 用户等级记录所属商户
     */
    public function merchantRegister()
    {
        return $this->belongsTo(MerchantRegister::class, 'merchant_id','id');
    }
}
